package lgs

import (
	"fmt"
	"log"
	"strings"
)

type IWrite struct {
	bs []byte
	s  string
}

func (this *IWrite) Write(p []byte) (n int, err error) {
	this.bs = p
	this.s = strings.ReplaceAll(string(this.bs), string('\n'), "")
	return len(p), nil
}

func (this *IWrite) String() string {
	return this.s
}

func (this *IWrite) string() string {
	return this.s
}

func (this *IWrite) data() []byte {
	return this.bs
}

func newWrite(prefix string, level int, s ...interface{}) *IWrite {
	w := &IWrite{}
	log.New(w, "["+prefix+"] ", log.Ldate|log.Ltime|log.Lshortfile).Output(level, fmt.Sprint(s...))
	return w
}

//----------------------------------
